﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using Sireass.Bl.Security;

namespace Sireass.Asp
{
    public class Global : System.Web.HttpApplication
    {

        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
			log4net.Config.XmlConfigurator.Configure();
        }

        void Application_End(object sender, EventArgs e)
        {
            //  Code that runs on application shutdown

        }

        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

        }

        void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started

        }

        void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.

        }

		protected void Application_AcquireRequestState(object sender, EventArgs e)
		{
			var identity = HttpContext.Current.User.Identity;
			if (identity.IsAuthenticated)
			{
				SireassPrincipal.Load(identity.Name);
			}
			//else
			//{
			//    // first time user has hit this site
			//    // for the sample, hard-code a login
			//    // normally this entire else block would
			//    // not exist
			//    SireassPrincipal.Login("juan.perez", "juan.perez");
			//    if (Csla.ApplicationContext.User.Identity.IsAuthenticated)
			//        FormsAuthentication.SetAuthCookie(Csla.ApplicationContext.User.Identity.Name, false);
			//}
			//if (Csla.ApplicationContext.User.Identity.IsAuthenticated && Csla.ApplicationContext.AuthenticationType == "Windows")
			//    Csla.ApplicationContext.ClientContext["Username"] = Csla.ApplicationContext.User.Identity.Name;
		}

    }
}
